{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以下是一个简单的文生图的案例，使用的千帆SDK版本为：\n",
    "```\n",
    "qianfan >= 0.1.2\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 安装依赖\n",
    "# install your dependency\n",
    "!pip install pillow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"QIANFAN_AK\"]=\"your_ak\"\n",
    "os.environ[\"QIANFAN_SK\"]=\"your_sk\"\n",
    "\n",
    "import qianfan\n",
    "from PIL import Image \n",
    "import io\n",
    "\n",
    "t2i = qianfan.Text2Image()\n",
    "resp = t2i.do(prompt=\"A Ragdoll cat with a bowtie.\", with_decode=\"base64\")\n",
    "img_data = resp[\"body\"][\"data\"][0][\"image\"]\n",
    "\n",
    "img = Image.open(io.BytesIO(img_data))\n",
    "display(img)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "139b939db84dfebabec3780f720b641581a25a15fcc080032fea5abf0322749f"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
